package com.wc.acwing.动态规划.期望DP.Q4649_爬树的甲壳虫;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/25 20:51
 * @description https://www.acwing.com/problem/content/4649/
 */
public class Main {
    /**
     * 思路流程：
     * Xi表示 从高度i到树顶n的事件
     * f[i] = E(Xi)  数学期望
     * 从 i 到 i + 1 成功概率为1 - p_i+1, 失败为p_i+1
     *
     * 括号里面 +1 表示从Xi到Xi+1或是Xo的一步
     * 所以Xi = (1 - p_i+1)(Xi+1 + 1) + p_i+1(Xo + 1)
     * <p>
     * E(Xi) = E((1 - p_i+1)(Xi+1 + 1) + p_i+1(Xo + 1))
     * = (1 - p_i+1)E(Xi+1) + p_i+1E(Xo) + 1
     * = (1 - p_i+1)E(Xi+1) - (1 - p_i+1)E(Xo) + 1 + E(Xo)
     *
     * E(Xi) - E(Xo) = (1 - p_i+1)(E(Xi+1) - E(Xo))
     * f[i] - f[0] = (1 - p_i+1)(f[i+1] - f[0]) + 1
     * <p>
     * 设g[i] = f[0] - f[i]
     * g[i] = (1 - p_i+1) g[i+1] - 1
     * g[i+1] = (g[i] + 1)/(1 - p_i+1)
     * g[i+1] = (g[i] + 1) * yi+1/(yi+1 - xi+1)
     *
     * g[0] = f[0] - f[0] = 0
     *
     * f[n] = E(Xn) = 0
     * g[n] = f[0] - f[n] = f[0]
     * 相当于求g[n] 也就是从0点到树根的位置
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int P = 998244353;
    static int n, x, y;

    public static void main(String[] args) {
        n = sc.nextInt();
        long res = 0;
        while (n-- > 0) {
            x = sc.nextInt();
            y = sc.nextInt();
            res = (res + 1) * y % P * qkm(y - x, P - 2) % P;
        }
        out.println(res);
        out.flush();
    }

    static long qkm(long a, int b) {
        long res = 1;
        while (b > 0) {
            if ((b & 1) == 1) res = res * a % P;
            b >>= 1;
            a = a * a % P;
        }
        return res;
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}